package com.smart.member.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.qf.common.result.ResponseResult;
import com.smart.coupon.template.dto.CouponDTO;
import com.smart.member.common.dto.SmsInfoDto;
import com.smart.member.feign.CouponService;
import com.smart.member.msg.DefaultSendCallback;
import com.smart.member.service.MemberService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Resource
    CouponService couponService;
    @Resource
    RocketMQTemplate rocketMQTemplate;

    @Resource

    @Override
    public ResponseResult<List<CouponDTO>> getCouponList(Long memberId) {
        return couponService.list(memberId);
    }

    @Override
    public Integer getVerificationCode(String phone) {
        String code = RandomUtil.randomNumbers(6);
        rocketMQTemplate.asyncSend("member-veri-code", MessageBuilder.withPayload(SmsInfoDto.builder().code(code).phone(phone).build()), new DefaultSendCallback());
        return 1;
    }
}
